//
//  EMFirstPageViewController.m
//  ElectronicMall
//
//  Created by 史伟文 on 14/12/21.
//  Copyright (c) 2014年 cczu. All rights reserved.
//

#import "EMFirstPageViewController.h"
#import "UINavigationController+EMNavi.h"
// 本店特销、每日特价、最新上市 复用的viewController
#import "EMSellingWellViewController.h"
#import "EMMyOrderViewController.h"
#import "EMEnterDefeatViewController.h"

#import "EMEnterDefeatViewController.h"

#import "EMCityChooseViewController.h"
#import "EMSearchViewController.h"

#import "EMSearchBar.h"
#import "EMFirstLayout.h"
#import "EMFirstHeaderView.h"
#import "EMFirstCellTitle.h"
#import "EMFirstCell80x100.h"


#import "EMDetailInfoViewController.h"
#import "MBProgressHUD.h"
#import "AppDelegate.h"
#import "EMGoodListReqBody.h"
#import "EMGoodListRespBody.h"
#import "EMGetAdPicReqBody.h"
#import "EMGetAdPicRespBody.h"
#import "UIImageView+WebCache.h"

#import "EMADBigCell.h"
#import "EMADMiddleCell.h"
#import "EMADSmallCell.h"
#import "EMGDBigCell.h"
#import "EMGDMiddleCell.h"
#import "EMGDSmallCell.h"
#import "EMGoodInfo3.h"
#import "UserInfo.h"
#import "EMLoginViewController.h"

@interface EMFirstPageViewController ()
{
    UITextField *tf0;
    NSArray *colorArray;
    NSArray *iconArray;
    NSArray *titleArray;
    AppDelegate *app;
    
    NSArray *topGoodImgArray;
    NSArray *enterDefeatImgArray;
    NSArray *newGoodArray;
    NSArray *newGoodAdArray;
    NSArray *groupAdArray;
    NSArray *saleGoodArray;
    NSString *noGoodPic;
}
@end

@implementation EMFirstPageViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.barTintColor = RGB(255, 255, 255);
    topGoodImgArray = [[NSArray alloc] init];
    enterDefeatImgArray = [[NSArray alloc] init];
    newGoodArray = [[NSArray alloc] init];
    newGoodAdArray = [[NSArray alloc] init];
    groupAdArray = [[NSArray alloc] init];
    saleGoodArray = [[NSArray alloc] init];
    noGoodPic = [[NSString alloc] init];
    [self getAdPic];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    self.view.backgroundColor = [UIColor whiteColor];
    iconArray = @[[UIImage imageNamed:@"icon_热销"],[UIImage imageNamed:@"icon_特价"],[UIImage imageNamed:@"icon_最新"],[UIImage imageNamed:@"icon_订单"],];
    titleArray = @[@"本店热销",@"每日特价",@"最新上市",@"我的订单",];
    
    
    EMSearchBar *search = [[EMSearchBar alloc] initWithFrame:CGRectMake(0, 0, 140, 24)];
    search.placeholderText = @"点击搜索商品";
    for (UIView *tf in search.subviews) {
        if ([tf isKindOfClass:[UITextField class]]) {
            tf0 = (UITextField *)tf;
        }
    }
    tf0.delegate = self;
    self.navigationItem.titleView = search;
    
    UIBarButtonItem *logoImage = [[UIBarButtonItem alloc] init];
    UIImage *imageQ = [UIImage imageNamed:@"logo_导航"];
    UIImageView *leftView = [[UIImageView alloc] initWithImage:[imageQ imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    leftView.frame = CGRectMake(0, 0, 90, 23);
    logoImage.customView = leftView;
    self.navigationItem.leftBarButtonItem = logoImage;
    
    UIButton *cityButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cityButton.frame = CGRectMake(270, 6, 60, 24);
    [cityButton setImage:[UIImage imageNamed:@"icon_地址选择"] forState:UIControlStateNormal];
    [cityButton setTitle:@"南京" forState:UIControlStateNormal];
    [cityButton setTitleColor:RGB(101, 118, 32) forState:UIControlStateNormal];
    cityButton.titleLabel.font = [UIFont fontWithName:HEITIMEDIUM size:14];
    [cityButton addTarget:self action:@selector(chooseCity:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *cityItem = [[UIBarButtonItem alloc] init];
    cityItem.customView = cityButton;
    self.navigationItem.rightBarButtonItem = cityItem;
    
    
    EMFirstLayout *layout = [[EMFirstLayout alloc] init];
    
    UICollectionView *firstCollectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];
    
    [firstCollectionView registerClass:[EMADBigCell class] forCellWithReuseIdentifier:@"bigADCell"];
    [firstCollectionView registerClass:[EMADMiddleCell class] forCellWithReuseIdentifier:@"middleADCell"];
    [firstCollectionView registerClass:[EMADSmallCell class] forCellWithReuseIdentifier:@"smallADCell"];
    [firstCollectionView registerClass:[EMGDBigCell class] forCellWithReuseIdentifier:@"bigGDCell"];
    [firstCollectionView registerClass:[EMGDMiddleCell class] forCellWithReuseIdentifier:@"middleGDCell"];
    [firstCollectionView registerClass:[EMGDSmallCell class] forCellWithReuseIdentifier:@"smallGDCell"];
    
    [firstCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell011"];
    [firstCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cells0"];
    [firstCollectionView registerClass:[EMFirstCell80x100 class] forCellWithReuseIdentifier:@"cells1"];

    [firstCollectionView registerClass:[EMFirstCellTitle class] forCellWithReuseIdentifier:@"cells10"];
    [firstCollectionView registerClass:[EMFirstCellTitle class] forCellWithReuseIdentifier:@"cells20"];

    [firstCollectionView registerClass:[EMFirstCellTitle class] forCellWithReuseIdentifier:@"cells30"];
    [firstCollectionView registerClass:[EMFirstCellTitle class] forCellWithReuseIdentifier:@"cells50"];


    firstCollectionView.delegate = self;
    firstCollectionView.dataSource = self;
    firstCollectionView.backgroundColor = [UIColor lightGrayColor];
    firstCollectionView.bounces = NO;
    [self.view addSubview:firstCollectionView];
}
- (void)chooseCity:(UIButton *)sender
{
//    EMCityChooseViewController *controller = [[EMCityChooseViewController alloc] init];
//    [self presentViewController:controller animated:YES completion:nil];
//    EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
//    controller.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:controller animated:YES];
    
}
#pragma mark - TextField delegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    EMSearchViewController *controller = [[EMSearchViewController alloc] init];
    UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:controller];
    [self presentViewController:navi2 animated:YES completion:nil];
}
#pragma mark - Image Scroll View Delegate and Datesource
- (NSInteger)numberOfPages
{
    return topGoodImgArray.count;
}

- (UIView *)pageAtIndex:(NSInteger)index
{
    NSArray *topInfo = topGoodImgArray[index];
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, W(320), H(160))];
    [view sd_setImageWithURL:[NSURL URLWithString:topInfo[1]]];

    return view;
}

- (void)didClickPage:(EMImageScrollView *)csView atIndex:(NSInteger)index
{
    NSArray *topInfo = topGoodImgArray[index];
    EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
    controller.goodID = topInfo[0];
    controller.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:controller animated:YES];
}

#pragma mark - UICollectionView delegate and datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 5;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    NSArray *itemNumArray = @[@1, @4, @5, @8, @8];
    return [itemNumArray[section] integerValue];

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.section == 0) {
        static NSString *cellIdentifier = @"cells0";
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
        while ([cell.subviews lastObject] != nil) {
            [(UIView *)[cell.subviews lastObject] removeFromSuperview];
        }

        EMImageScrollView *csView = [[EMImageScrollView alloc] initWithFrame:CGRectMake(0, 0, W(320), H(160))];
        csView.delegate = self;
        csView.datasource = self;
        [cell addSubview:csView];
        return cell;
    } else if (indexPath.section == 1) {
        
        static NSString *cellIdentifier = @"cells1";
        EMFirstCell80x100 *cell = (EMFirstCell80x100 *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
        while ([cell.subviews lastObject] == nil) {
            [(UIView *)[cell.subviews lastObject] removeFromSuperview];
        }

        cell.icon.image = iconArray[indexPath.item];
        cell.title.text = titleArray[indexPath.item];
        cell.backgroundColor = RGB(240, 240, 240);
        return cell;
    } else if (indexPath.section == 2) {
        if (indexPath.item == 0) {
            static NSString *cellIdentifier = @"cells10";
            EMFirstCellTitle *cell = (EMFirstCellTitle *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            cell.titleLabel.text = @"进店必败";
            return cell;
        } else if (indexPath.item == 1) {
            static NSString *cellIdentifier = @"bigADCell";
            EMADBigCell *cell = (EMADBigCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            if (enterDefeatImgArray.count < 1) {
                [cell.bigADCell sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
            } else {
                NSArray *array = enterDefeatImgArray[0];
                [cell.bigADCell sd_setImageWithURL:[NSURL URLWithString:array[1]]];
            }
           
            return cell;
        } else if (indexPath.item == 2) {
            static NSString *cellIdentifier = @"middleADCell";
            EMADMiddleCell *cell = (EMADMiddleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            if (enterDefeatImgArray.count < 2) {
                [cell.middleADCell sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
            } else {
                NSArray *array = enterDefeatImgArray[1];
                [cell.middleADCell sd_setImageWithURL:[NSURL URLWithString:array[1]]];
            }
            
            return cell;
        } else if (indexPath.item == 3) {
            static NSString *cellIdentifier = @"smallADCell";
            EMADSmallCell *cell = (EMADSmallCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            if (enterDefeatImgArray.count < 3) {
                [cell.smallADCell sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
            } else {
                NSArray *array = enterDefeatImgArray[2];
                [cell.smallADCell sd_setImageWithURL:[NSURL URLWithString:array[1]]];
            }
            return cell;
        } else {
            static NSString *cellIdentifier = @"smallADCell";
            EMADSmallCell *cell = (EMADSmallCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            if (enterDefeatImgArray.count < 4) {
                [cell.smallADCell sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
            } else {
                NSArray *array = enterDefeatImgArray[3];
                [cell.smallADCell sd_setImageWithURL:[NSURL URLWithString:array[1]]];
            }
            return cell;
        }
        
    } else if (indexPath.section == 3) {
        if (indexPath.item == 0) {
            static NSString *cellIdentifier = @"cells20";
            EMFirstCellTitle *cell = (EMFirstCellTitle *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            cell.titleLabel.text = @"新品上市";
            return cell;
        } else if (indexPath.item == 1 || indexPath.item == 2 || indexPath.item == 4 || indexPath.row == 5) {
            static NSString *cellIdentifier = @"smallGDCell";
            EMGDSmallCell *cell = (EMGDSmallCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            switch (indexPath.item) {
                case 1:
                {
                    UIView *rLine = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 0.5, 10, 0.5, cell.frame.size.height - 10)];
                    rLine.backgroundColor = [UIColor lightGrayColor];
                    [cell addSubview:rLine];
                    UIView *bLine = [[UIView alloc] initWithFrame:CGRectMake(10, cell.frame.size.height - 0.5, cell.frame.size.width - 10, 0.5)];
                    bLine.backgroundColor = [UIColor lightGrayColor];
                    [cell addSubview:bLine];
                    if (newGoodArray.count < 1) {
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                        cell.goodName.text = @" ";
                        cell.nowPrice.text = @" ";
                        cell.originPrice.text = @" ";
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[0]];
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                        cell.goodName.text = info.m_name;
                        cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                        NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                        [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                        cell.originPrice.attributedText = oPrice;
                    }
                    break;
                }
                case 2:
                {
                    UIView *bLine = [[UIView alloc] initWithFrame:CGRectMake(0, cell.frame.size.height - 0.5, cell.frame.size.width - 10, 0.5)];
                    bLine.backgroundColor = [UIColor lightGrayColor];
                    [cell addSubview:bLine];
                    if (newGoodArray.count < 2) {
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                        cell.goodName.text = @" ";
                        cell.nowPrice.text = @" ";
                        cell.originPrice.text = @" ";
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[1]];
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                        cell.goodName.text = info.m_name;
                        cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                        NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                        [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                        cell.originPrice.attributedText = oPrice;
                    }
                    break;
                }
                case 4:
                {
                    UIView *rLine = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 0.5, 0, 0.5, cell.frame.size.height - 10)];
                    rLine.backgroundColor = [UIColor lightGrayColor];
                    [cell addSubview:rLine];
                    if (newGoodArray.count < 3) {
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                        cell.goodName.text = @" ";
                        cell.nowPrice.text = @" ";
                        cell.originPrice.text = @" ";
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[2]];
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                        cell.goodName.text = info.m_name;
                        cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                        NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                        [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                        cell.originPrice.attributedText = oPrice;
                    }
                    break;
                }
                case 5:
                {
                    if (newGoodArray.count < 4) {
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                        cell.goodName.text = @" ";
                        cell.nowPrice.text = @" ";
                        cell.originPrice.text = @" ";
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[3]];
                        [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                        cell.goodName.text = info.m_name;
                        cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                        NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                        [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                        cell.originPrice.attributedText = oPrice;
                    }
                    break;
                }
                default:
                    break;
            }
            return cell;
            
        } else if (indexPath.item == 3) {
            static NSString *cellIdentifier = @"bigADCell";
            EMADBigCell *cell = (EMADBigCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            UIView *lLine = [[UIView alloc] initWithFrame:CGRectMake(0, 10, 0.5, cell.frame.size.height - 10)];
            lLine.backgroundColor = [UIColor lightGrayColor];
            [cell addSubview:lLine];
            if (newGoodAdArray.count != 0) {
                NSArray *array = newGoodAdArray[0];
                [cell.bigADCell sd_setImageWithURL:[NSURL URLWithString:array[1]]];
            } else {
                [cell.bigADCell sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];;
            }
            
            return cell;
        } else {
            static NSString *cellIdentifier = @"middleGDCell";
            EMGDMiddleCell *cell = (EMGDMiddleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            if (indexPath.item == 6) {
                UIView *tLine = [[UIView alloc] initWithFrame:CGRectMake(10, 0, cell.frame.size.width - 10, 0.5)];
                tLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:tLine];
                UIView *rLine = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 0.5, 0, 0.5, cell.frame.size.height - 10)];
                rLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:rLine];
                if (newGoodArray.count < 5) {
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                    cell.goodName.text = @" ";
                    cell.priceLabel.text = @" ";
                    cell.originPriceLabel.text = @" ";
                    cell.goodDesc.text = @" ";
                } else {
                    EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[4]];
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                    cell.goodName.text = info.m_name;
                    cell.goodDesc.text = (NSNull *)info.m_goodDesc == [NSNull null] ? @"" : info.m_goodDesc;
                    cell.priceLabel.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                    NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                    [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                    cell.originPriceLabel.attributedText = oPrice;
                }
            } else {
                UIView *tLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width - 10, 0.5)];
                tLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:tLine];
                if (newGoodArray.count < 6) {
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                    cell.goodName.text = @" ";
                    cell.priceLabel.text = @" ";
                    cell.originPriceLabel.text = @" ";
                    cell.goodDesc.text = @" ";
                } else {
                    EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[5]];
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                    cell.goodName.text = info.m_name;
                    cell.goodDesc.text = (NSNull *)info.m_goodDesc == [NSNull null] ? @"" : info.m_goodDesc;
                    cell.priceLabel.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                    NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                    [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                    cell.originPriceLabel.attributedText = oPrice;
                }
            }
            return cell;
        }

    } else {
        if (indexPath.item == 0) {
            static NSString *cellIdentifier = @"cells50";
            EMFirstCellTitle *cell = (EMFirstCellTitle *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            cell.titleLabel.text = @"团购活动";
            return cell;
        } else if (indexPath.item == 1) {
            static NSString *cellIdentifier = @"bigGDCell";
            EMGDBigCell *cell = (EMGDBigCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            UIView *rLine = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 0.5, 10, 0.5, cell.frame.size.height - 20)];
            rLine.backgroundColor = [UIColor lightGrayColor];
            [cell addSubview:rLine];
            
            if (saleGoodArray.count < 1) {
                [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                cell.goodName.text = @" ";
                cell.goodPrice.text = @" ";
                cell.originPrice.text = @" ";
            } else {
                EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[0]];
                [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                cell.goodName.text = info.m_name;
                cell.goodPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                cell.originPrice.attributedText = oPrice;
            }

            return cell;
        } else if (indexPath.item == 2) {
            static NSString *cellIdentifier = @"middleADCell";
            EMADMiddleCell *cell = (EMADMiddleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            UIView *bLine = [[UIView alloc] initWithFrame:CGRectMake(10, cell.frame.size.height - 0.5, cell.frame.size.width - 10, 0.5)];
            bLine.backgroundColor = [UIColor lightGrayColor];
            [cell addSubview:bLine];
            if (groupAdArray.count != 0) {
                NSArray *array = groupAdArray[0];
                [cell.middleADCell sd_setImageWithURL:[NSURL URLWithString:array[1]]];
            } else {
                [cell.middleADCell sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];;
            }
            
            return cell;
        } else {
            static NSString *cellIdentifier = @"smallGDCell";
            EMGDSmallCell *cell = (EMGDSmallCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
            while ([cell.subviews lastObject] == nil) {
                [(UIView *)[cell.subviews lastObject] removeFromSuperview];
            }
            if (indexPath.item == 3) {
                UIView *rLine = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 0.5, 10, 0.5, cell.frame.size.height - 20)];
                rLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:rLine];
                if (saleGoodArray.count < 2) {
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                    cell.goodName.text = @" ";
                    cell.nowPrice.text = @" ";
                    cell.originPrice.text = @" ";
                } else {
                    EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[1]];
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                    cell.goodName.text = info.m_name;
                    cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                    NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                    [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                    cell.originPrice.attributedText = oPrice;
                }
            } else if (indexPath.item == 4) {
                if (saleGoodArray.count < 3) {
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                    cell.goodName.text = @" ";
                    cell.nowPrice.text = @" ";
                    cell.originPrice.text = @" ";
                } else {
                    EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[2]];
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                    cell.goodName.text = info.m_name;
                    cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                    NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                    [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                    cell.originPrice.attributedText = oPrice;                }
            } else if (indexPath.item == 5) {
                UIView *rLine = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 0.5, 10, 0.5, cell.frame.size.height - 10)];
                rLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:rLine];
                UIView *tLine = [[UIView alloc] initWithFrame:CGRectMake(10, 0, cell.frame.size.width, 0.5)];
                tLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:tLine];
                if (saleGoodArray.count < 4) {
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                    cell.goodName.text = @" ";
                    cell.nowPrice.text = @" ";
                    cell.originPrice.text = @" ";
                } else {
                    EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[3]];
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                    cell.goodName.text = info.m_name;
                    cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                    NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                    [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                    cell.originPrice.attributedText = oPrice;
                }
            } else if (indexPath.item == 6) {
                UIView *rLine = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.size.width - 0.5, 10, 0.5, cell.frame.size.height - 10)];
                rLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:rLine];
                UIView *tLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 0.5)];
                tLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:tLine];
                if (saleGoodArray.count < 5) {
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                    cell.goodName.text = @" ";
                    cell.nowPrice.text = @" ";
                    cell.originPrice.text = @" ";
                } else {
                    EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[4]];
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                    cell.goodName.text = info.m_name;
                    cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                    NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                    [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                    cell.originPrice.attributedText = oPrice;
                }
            } else {
                UIView *tLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width - 10, 0.5)];
                tLine.backgroundColor = [UIColor lightGrayColor];
                [cell addSubview:tLine];
                if (saleGoodArray.count < 6) {
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:noGoodPic]];
                    cell.goodName.text = @" ";
                    cell.nowPrice.text = @" ";
                    cell.originPrice.text = @" ";
                } else {
                    EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[5]];
                    [cell.goodImage sd_setImageWithURL:[NSURL URLWithString:info.m_imgUrl]];
                    cell.goodName.text = info.m_name;
                    cell.nowPrice.text = [NSString stringWithFormat:@"¥%@", info.m_nowPrice];
                    NSMutableAttributedString *oPrice = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@", info.m_originPrice]];
                    [oPrice addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, info.m_originPrice.length+1)];
                    cell.originPrice.attributedText = oPrice;
                }
            }
            return cell;
        }

    }
    
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    UIEdgeInsets top = {0, 0, 0, 0};
    return top;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize itemSize;
    switch (indexPath.section) {
        case 0:
        {
            itemSize = CGSizeMake(W(320), H(160));
            break;
        }
        case 1:
        {
            itemSize = CGSizeMake(W(80), H(100));
            break;
        }
        case 2:
        {
            if (indexPath.item == 0) {
                itemSize = CGSizeMake(W(320), H(30));
            } else if (indexPath.item == 1) {
                itemSize = CGSizeMake(W(140), H(180));
            } else if (indexPath.item == 2) {
                itemSize = CGSizeMake(W(180), H(90));
            } else {
                itemSize = CGSizeMake(W(90), H(90));
            }
            break;
        }
        case 3:
        {
            if (indexPath.item == 0) {
                itemSize = CGSizeMake(W(320), H(30));
            } else if (indexPath.item == 3) {
                itemSize = CGSizeMake(W(140), H(180));
            } else if (indexPath.item == 6 || indexPath.item == 7) {
                itemSize = CGSizeMake(W(160), H(80));
            } else {
                itemSize = CGSizeMake(W(90), H(90));
            }
            break;
        }

        case 4:
        {
            if (indexPath.item == 0) {
                itemSize = CGSizeMake(W(320), H(30));
            } else if (indexPath.item == 1) {
                itemSize = CGSizeMake(W(140), H(180));
            } else if (indexPath.item == 2) {
                itemSize = CGSizeMake(W(180), H(90));
            } else if (indexPath.item == 3 || indexPath.item == 4) {
                itemSize = CGSizeMake(W(90), H(90));
            } else if (indexPath.item == 6) {
                itemSize = CGSizeMake(W(106), H(90));
            } else {
                itemSize = CGSizeMake(W(107), H(90));
            }
            break;
        }

        default:
            break;
    }
    return itemSize;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    if (section == 0 || section == 1) {
        return CGSizeMake(W(320), 0);
    } else {
        return CGSizeMake(W(320), 10);
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"seciton=%ld-row=%ld", (long)indexPath.section, (long)indexPath.row);
    switch (indexPath.section) {
        case 1:
        {
            switch (indexPath.row) {
                case 0:
                {// 本店热销
                    EMSellingWellViewController *controller = [[EMSellingWellViewController alloc] init];
                    controller.hidesBottomBarWhenPushed = YES;
                    controller.titleString = @"本店热销";
                    controller.judgeMethod = @"GOOD-HOT-LIST-PAGE";
                    controller.judgeFlag = @"4";
                    [self.navigationController pushViewController:controller animated:YES];
                    break;
                }
                case 1:
                {
                    EMSellingWellViewController *controller = [[EMSellingWellViewController alloc] init];
                    controller.hidesBottomBarWhenPushed = YES;
                    controller.titleString = @"每日特价";
                    controller.judgeMethod = @"GOOD-EVERYDAY-LIST-PAGE";
                    controller.judgeFlag = @"1";
                    [self.navigationController pushViewController:controller animated:YES];
                    break;
                }
                case 2:
                {
                    EMSellingWellViewController *controller = [[EMSellingWellViewController alloc] init];
                    controller.hidesBottomBarWhenPushed = YES;
                    controller.titleString = @"最新上市";
                    controller.judgeMethod = @"GOOD-NEW-LIST-PAGE";
                    controller.judgeFlag = @"3";
                    [self.navigationController pushViewController:controller animated:YES];
                    break;
                }
                case 3:
                {
                    if ([UserInfo sharedUserInfo].m_isLogin) {
                        EMMyOrderViewController *controller = [[EMMyOrderViewController alloc] init];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    } else {
                        EMLoginViewController *controller = [[EMLoginViewController alloc] init];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                default:
                    break;
            }
            break;
        }
        case 2:
        {
            switch (indexPath.row) {
                case 0:
                {
                    EMEnterDefeatViewController *controller = [[EMEnterDefeatViewController alloc] init];
                    controller.hidesBottomBarWhenPushed = YES;
                    controller.judgeFlag = @"1";
                    [self.navigationController pushViewController:controller animated:YES];
                    break;
                }
                case 1:
                {
                    if (enterDefeatImgArray.count < 1) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        NSArray *array = enterDefeatImgArray[0];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = array[0];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 2:
                {
                    if (enterDefeatImgArray.count < 2) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        NSArray *array = enterDefeatImgArray[1];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = array[0];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 3:
                {
                    if (enterDefeatImgArray.count < 3) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        NSArray *array = enterDefeatImgArray[2];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = array[0];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 4:
                {
                    if (enterDefeatImgArray.count < 4) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        NSArray *array = enterDefeatImgArray[3];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = array[0];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                default:
                    break;
            }
            break;
        }
        case 3:
        {
            switch (indexPath.row) {
                case 0:
                {
                    EMEnterDefeatViewController *controller = [[EMEnterDefeatViewController alloc] init];
                    controller.hidesBottomBarWhenPushed = YES;
                    controller.judgeFlag = @"2";
                    [self.navigationController pushViewController:controller animated:YES];
                    break;
                }
                case 1:
                {
                    if (newGoodArray.count < 1) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[0]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 2:
                {
                    if (newGoodArray.count < 2) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[1]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 3:
                {
                    if (newGoodAdArray.count < 1) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        NSArray *array = newGoodAdArray[0];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = array[0];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 4:
                {
                    if (newGoodArray.count < 3) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[2]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 5:
                {
                    if (newGoodArray.count < 4) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[3]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 6:
                {
                    if (newGoodArray.count < 5) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[4]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 7:
                {
                    if (newGoodArray.count < 6) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:newGoodArray[5]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                default:
                    break;
            }
            break;
        }

        case 4:
        {
            switch (indexPath.row) {
                case 0:
                {
                    EMEnterDefeatViewController *controller = [[EMEnterDefeatViewController alloc] init];
                    controller.hidesBottomBarWhenPushed = YES;
                    controller.judgeFlag = @"4";
                    [self.navigationController pushViewController:controller animated:YES];
                    break;
                }
                case 1:
                {
                    if (saleGoodArray.count < 1) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[0]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 2:
                {
                    if (groupAdArray.count < 1) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        NSArray *array = groupAdArray[0];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = array[0];
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 3:
                {
                    if (saleGoodArray.count < 2) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[1]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 4:
                {
                    if (saleGoodArray.count < 3) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[2]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 5:
                {
                    if (saleGoodArray.count < 4) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[3]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 6:
                {
                    if (saleGoodArray.count < 5) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[4]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                case 7:
                {
                    if (saleGoodArray.count < 6) {
                        [app showTip:@"没有商品哦！"];
                    } else {
                        EMGoodInfo3 *info = [[EMGoodInfo3 alloc] initWithEnterGoodInfo:saleGoodArray[5]];
                        EMDetailInfoViewController *controller = [[EMDetailInfoViewController alloc] init];
                        controller.goodID = info.m_id;
                        controller.hidesBottomBarWhenPushed = YES;
                        [self.navigationController pushViewController:controller animated:YES];
                    }
                    break;
                }
                default:
                    break;
            }
            break;
        }

        default:
            break;
    }
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

// 获取首页广告图片
- (void)getAdPic
{
    [MBProgressHUD  showHUDAddedTo:self.navigationController.view animated:YES];
    EMGetAdPicReqBody *reqBody = [[EMGetAdPicReqBody alloc] init];
    reqBody.JUDGEMETHOD = @"INDEX-GOODS-INFO";
    
    HessianFormDataRequest *request = [[HessianFormDataRequest alloc] init];
    // 模型转字典
    request.postData = reqBody.keyValues;
    [request startRequestWithURL:baseURL andCompletionBlcok:^(NSDictionary *respInfo) {
        // 将返回的字典转成模型，键的名称必须相同
        EMGetAdPicRespBody *respBody = [EMGetAdPicRespBody objectWithKeyValues:respInfo];
        [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
        if ([respBody.ERRORCODE isEqualToString: @"0000"]) {
            topGoodImgArray = respBody.CAROUSELAD;
            enterDefeatImgArray = respBody.INTOSTORELOSTAD;
            newGoodAdArray = respBody.NEWGOODSAD;
            newGoodArray = respBody.NEWGOODS;
            groupAdArray = respBody.GROUPBUYAD;
            saleGoodArray = respBody.SALEGOODS;
            noGoodPic = respBody.NOPIC;
        } else {
            [app showTip:respInfo[@"ERRORDESTRIPTION"]];
        }
    } andFailedBlock:^{
        
        [app showTip:@"无法连接服务器、请稍后再试"];
    }];
    
}

@end
